﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A60StringBuilder类
{
    class Program
    {
        //如果多个字符串直接相加会产生很多垃圾 浪费内存
        static void Main1(string[] args)
        {
            string[] arr = { "C#", "Java", "C++", "Python", "Lua", "JavaScript" };
            string sum = "";
            for (int i = 0; i < arr.Length; i++)
            {
                sum += arr[i];
            }
            Console.WriteLine(sum);
        }
        //优化的做法 使用StringBulder
        static void Main(string[] args)
        {
            string[] arr = { "C#", "Java", "C++", "Python", "Lua", "JavaScript" };
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < arr.Length; i++)
            {
                // sb.Append(arr[i]); //追加  记录每一个字符串的地址
                //sb.AppendLine(arr[i]); //一个字符串一行
                sb.AppendFormat("{0}:{1}\t",i,arr[i]);
            }
            string str = sb.ToString();//一次性做成新字符串
   
        }
    }
}
